import java.util.ArrayList;


public class TimeEventSender {
	
	ArrayList<TimeEventListener> listListeners = new ArrayList<TimeEventListener>();
	
	public void generateTimeEvent(String message)
	{
		TimeEvent event= new TimeEvent(this, message);
		
		for(TimeEventListener each : listListeners)
		{
			each.receiveEvent(event);
		}
	}
	
	public void generateTimeOutEvent(String message, int attente) throws InterruptedException
	{
		
		TimeOutEvent event = new TimeOutEvent(this, attente, message);
		
		Thread.sleep(attente);
		
		for(int i=0; i<listListeners.size(); i++)
		{
			listListeners.get(i).receiveEvent( event);
		}
	}
	
	public void generatePeriodicTimeEvent(String message, int periode, int nb) throws InterruptedException
	{
		
		PeriodicTimeEvent event = new PeriodicTimeEvent(this, message, nb, periode);
		
		for (int j=1; j<=nb; j++)
		{
			Thread.sleep(periode);
		
			for(int i=0; i<listListeners.size(); i++)
			{
				listListeners.get(i).receiveEvent( event);
			}
		}
	}
	
	
	
	public void addReceiver(TimeEventListener listener)
	{
		listListeners.add(listener);
	}

}
